<template>
    <div class="type-wrapper">
        <ul class="type-list">
            <li :class="type === '-' && 'selected'"
                @click="selectType = '-'">支出
            </li>
            <li :class="type === '+' && 'selected'"
                @click="selectType = '+'">收入
            </li>
        </ul>
    </div>
</template>

<script lang="ts">
    import Vue from 'vue';
    import {Component, Prop, Watch} from 'vue-property-decorator';

    @Component
    export default class Type extends Vue {
        name = 'Type';
        selectType = '-'

        @Prop(String) type: string | undefined;

        @Watch('selectType')
        onSelectTypeChanged(selectType: string) {
            if (selectType !== '-' && selectType !== '+') {
                throw new Error('type is unknown');
            }
            this.$emit('update:type', selectType)
        }
    }
</script>

<style lang="scss" scoped>
    @import "~@/assets/style/helper.scss";

    .type-list {
        display: flex;
        box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);

        > li {
            font-size: 1.2em;
            padding-top: 5px;
            padding-bottom: 5px;
            width: 50%;
            line-height: 2em;
            color: $color-lightgray;
        }

        > li.selected {
            color: $color-orange;
            position: relative;

            &::after {
                content: '';
                position: absolute;
                width: 0;
                border-left: 10px solid transparent;
                border-right: 10px solid transparent;
                border-bottom: 10px solid $color-orange;
                left: 50%;
                bottom: 0;
                margin-left: -10px;
                transition: all 1s ease;
            }
        }
    }


</style>